{% extends 'myadmin/base.html' %}
{% block main_body %}
<style>
    .form-card {
        background: #fff;
        border-radius: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        padding: 20px;
    }
    .form-section {
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 1px solid #f1f1f1;
    }
    .form-row {
        display: flex;
        flex-wrap: wrap;
        margin: 0 -10px;
    }
    .form-col {
        flex: 1;
        min-width: 300px;
        padding: 0 10px;
        box-sizing: border-box;
    }
    .form-group {
        margin-bottom: 12px;
        width: 100%;
    }
    .form-group label {
        font-weight: 600;
        font-size: 13px;
        margin-bottom: 5px;
        display: block;
    }
    .form-control {
        width: 100%;
        padding: 6px 10px;
        font-size: 13px;
        height: 34px;
        box-sizing: border-box;
    }
    .required-mark {
        color: #dd4b39;
        margin-left: 3px;
    }
    .btn-group {
        margin-top: 15px;
        display: flex;
        gap: 10px;
        justify-content: flex-end;
    }
</style>

<section class="content-header">
    <h1>饮食记录管理 <small>添加记录</small></h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i> 首页</a></li>
        <li><a href="#">饮食记录管理</a></li>
        <li class="active">添加记录</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">添加饮食记录</h3>
                </div>
                <form method="post" action="{% url 'myadmin_userdietrecords_add' %}" class="form-card">
                    {% csrf_token %}
                    
                    <!-- 基础信息 -->
                    <div class="form-section">
                        <h4><i class="fa fa-cutlery"></i> 饮食记录信息</h4>
                        <div class="form-row">
                            <div class="form-col">
                                <div class="form-group">
                                    <label>用户 <span class="required-mark">*</span></label>
                                    <select name="user_id" class="form-control" required>
                                        <option value="">-- 请选择用户 --</option>
                                        {% for user in users %}
                                        <option value="{{ user.user_id }}">{{ user.username }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>食物 <span class="required-mark">*</span></label>
                                    <select name="food_id" class="form-control" required>
                                        <option value="">-- 请选择食物 --</option>
                                        {% for food in foods %}
                                        <option value="{{ food.food_id }}">{{ food.food_name }} ({{ food.calories_per_100g }}大卡/100g)</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>食用量(g) <span class="required-mark">*</span></label>
                                    <input type="number" name="quantity" class="form-control" min="0.1" step="0.1" required>
                                </div>
                            </div>
                            <div class="form-col">
                                <div class="form-group">
                                    <label>餐次类型 <span class="required-mark">*</span></label>
                                    <select name="meal_type" class="form-control" required>
                                        <option value="">-- 请选择餐次 --</option>
                                        {% for key, value in meal_types %}
                                        <option value="{{ key }}">{{ value }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>记录时间 <span class="required-mark">*</span></label>
                                    <input type="datetime-local" name="record_time" class="form-control" 
                                           value="{{ default_time }}" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 操作按钮 -->
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" onclick="window.history.back();">返回</button>
                        <button type="reset" class="btn btn-default">重置</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{% endblock %}